#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int col[N];
int row[N];
int s[N];
int n, m, q;
int c[N];
LL work(int a[] ,int n)
{
	for (int i = 1; i <= n; i++) {
		s[i] = s[i - 1] + a[i];
	}
	if (s[n] % n) {
		return -1;
	}
	int avg = s[n] / n;
	for (int i = 1; i <= n; i++) {
		c[i] = s[i - 1] - (i - 1) * avg;
	}
	sort(c + 1, c + n + 1);
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += abs(c[i] - c[(i + 1) / 2]);
	}
	return ans;
}
int main()
{
	cin >> n >> m >> q;
	while (q--) {
		int x, y;
		cin >> x >> y;
		row[x]++;
		col[y]++;
	}
	LL ans1 = work(row, n);
	LL ans2 = work(col, m);
	if (ans1 != -1 && ans2 != -1) {
		cout << "both " << ans1 + ans2 << endl;
	}
	else if (ans1 != -1) {
		cout << "row " << ans1 << endl;
	}
	else if (ans2 != -1) {
		cout << "column " << ans2 << endl;
	}
	else {
		cout << "impossible" << endl;
	}
	return 0;
}